package domfarr.tapestry.pages;

import java.util.ArrayList;
import java.util.List;

import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.SelectModel;
import org.apache.tapestry5.ValueEncoder;
import org.apache.tapestry5.ioc.annotations.Inject;

public class OrderHandling {
	
	@Inject
	private ComponentResources componentsResources;
	
	private List<Greeting> greetings;
	
	private ArrayList<Greeting> list;

	private ValueEncoder<Greeting> encoder;

	public OrderHandling() {
		this.list = new ArrayList<Greeting>();

		this.list.add(new Greeting("Grüzi", "SwissGerman"));
		this.list.add(new Greeting("Buenos Días", "Spanish"));
		
		this.encoder = new GreetingEncoder(list);
	}

	public List<Greeting> getGreeting() {
		return greetings;
	}

	public void setGreeting(List<Greeting> greetings) {
		this.greetings = greetings;
	}

	public SelectModel getGreetingSelectModel() {
		return new SpecialHandling(list);
	}

	public ValueEncoder<Greeting> getEncoder() {
		return this.encoder;
	}
	
	Object onSuccess() {
		return componentsResources.createPageLink(Index.class, false, this.greetings.get(0).getGreeting());
	}

}
